<template>
    <div class='commonList' v-loading="loading">
       
        <div class='commonList_title' v-if="isTitle=='Y'" ><i class='fa fa-info-circle'></i>{{title}}</div>
        <div class='commonList_title commonList_title_app2' v-if="isApp=='Y'&&isAppTop=='Y'" >  <i class='el-icon-arrow-left' @click="returns" style='margin-right:10px;float:left;line-height:30px'>返回</i><i class='fa fa-info-circle'></i>{{title}}</div>
        <div class='commonList_title commonList_title_app' v-if="isApp=='Y'&&isAppTop==''&&isYtj!='Y'" >  <i class='el-icon-arrow-left' @click="returns" style='margin-right:10px;float:left;line-height:30px'>返回</i><i class='fa fa-info-circle'></i>{{title}}</div>
        <div class='commonList_title commonList_title_ytj' v-if="isYtj=='Y'" >  <i class='el-icon-arrow-left' @click="returns" style='margin-right:10px;float:left;line-height:50px'>返回</i><i class='fa fa-info-circle'></i>{{title}}</div>
         <div v-if="buttonJson.length<=4&&tabJson.length>0&&tabJson.length<2">
            <search v-if="hidenSearch!='Y'&&searchStr.length>0" @search-event="searchEvent" :searchStr="searchStr" @tab-event="tabEvents"  ref="searchs" style='margin-bottom:5px;'></search>

             <el-row class='elrows' v-if="(buttonJson.length>0||tabJson.length>0)&&notButton!='Y'">
                <el-col :span="12" >
                    <tab-bar  :searchJson="searchStr2"  :tabJson="tabJson" @tab-event="tabEvent"></tab-bar>
                    
                </el-col>
                 <el-col :span="12">
                    <button-bar :buttonJson="buttonJson" @btn-click="btnClick" style='padding-top:10px'></button-bar>
                </el-col>
                
            </el-row>
         </div>
         <div v-else>
            
            <search v-if="hidenSearch!='Y'&&searchStr.length>0" @search-event="searchEvent"  @tab-event="tabEvents"   :searchStr="searchStr"  ref="searchs" style='margin-bottom:5px;'></search>

            <el-row class='elrows' v-if="buttonJson.length>0&&notButton!='Y'" >
                <el-col :span="24">
                    <button-bar :buttonJson="buttonJson" @btn-click="btnClick"></button-bar>
                </el-col>
                
            </el-row>
            <el-row v-if="tabJson.length>0"  class='elrows'>
                <el-col :span="24">
                    <tab-bar :tabJson="tabJson"  :searchJson="searchStr2"  @tab-event="tabEvent"></tab-bar>
                </el-col>
            </el-row>
            <div style='height:10px;background:#fff' v-else>&nbsp;</div>

         </div>
         

        <div class='tables' ref="tables"> 
            <template v-if="isPost!='Y'">

                <simple-table :company="company" @countJson="countJson" :buttons="buttonJsonRow" :listField="list" :model="model" selectType="multipleTable" ref="tableList" :noPage="noPage" @rowClick="rowClick" @empty="empty" @rowMultiClick="rowMultiClick" @rowDbClick="rowDbClick" @openWin="openWin" @prints="prints" @goSearch="goSearchs" :sKey="sKey" :exId="exId" :sKey2="sKey2" :url="url" :tabJson="tabJson2" :searchJson="searchStr2" :listname="listname" v-if="showTable&&listType=='simple'" :defaultOrder="defaultOrder" :multiOrder="multiOrder" :appid="appid" :model_key="model_key" :isSearch="isSearch2" :noclick="noclicks"></simple-table>
                <common-list-complex2 :searchJson="searchStr2" :company="company" :model="model" @rowClick="rowClick" :sKey="sKeyc" :sKey2="sKeyc2"  ref="tableList" v-if="listType=='complex'"   @rowMultiClick="rowMultiClick"  @rowDbClick="rowDbClick" :appid="appid" :model_key="model_key" ></common-list-complex2>
                <common-list-double2 :searchJson="searchStr2" :company="company" :model="model"  @rowClick="rowClick" :sKey="sKeyd" @empty="empty" :exkey="exkeyd" ref="tableList" v-if="listType=='double'" :appid="appid" :model_key="sKeyd2"  @rowDbClick="rowDbClick"></common-list-double2>
            </template>
            <div v-else v-html="contentHtml">
            </div>
        </div>
        
        <common-print :printDatas="printData" style='height:0' v-if="isDialogPrint=='N'" ></common-print>

         <el-dialog
            v-el-drag-dialog
            title="打印"
            class="dialogClass dialog-vertical3"
            width="80%"
            top="0"
            center
            style='left:0;top:0'
            :visible.sync="dialogVisible6"
            append-to-body
            >
             <common-print :printDatas="printData" style='height:0' v-if="isDialogPrint=='Y'"></common-print>
        </el-dialog>
    </div> 
  
</template>
 
<script>
    import Vue  from 'vue'
    import SimpleTable  from './SimpleTable.vue'
    import ButtonBar  from './ButtonBar.vue'
    import search  from './search.vue'
    import tabBar  from './TabBar.vue'
    import commonListComplex2  from './commonListComplex2.vue'
    import commonListDouble2  from './commonListDouble2.vue'
    import CommonPrint  from '../../views/common/print/CommonPrint.vue'
    import vueJsonEditor from 'vue-json-editor'
    import Sortable from 'sortablejs'
    export default {
        props:['notButton','isApp','sKey','sKey2','company','searchs','listnames','hidenSearch','searchJson','isTitle','index','exId','appid','model_key','model','isPost','isSearch','noclick'],
        name: "commonList",
        components: {
            vueJsonEditor,
            SimpleTable,
            ButtonBar,
            search,
            tabBar,
            commonListComplex2,
            commonListDouble2,
            CommonPrint,
            Sortable
        },
        data(){
            return {
                noclicks:"",
                isSearch2:this.isSearch,
                printData:{},
                listname:this.listnames,
                list:[],
                showTable:false,
                searchStr:[],
                buttonJson:[],
                buttonJsonRow:[],
                tabJson:[],
                tabJson2:[],
                searchStr2:[],
                curRow:null,
                curRows:null,
                loading:true,
                noPage:false,
                sKeyd:'',
                sKeyd2:'',
                sKeyc:'',
                sKeyc2:'',
                exkeyd:"",
                listType:'simple',
                url:'',/**请求后台url */
                title:'',
                defaultOrder:[],
                multiOrder:"N",
                dbModelkey:"",
                isAppTop:localStorage.getItem("isAppTop"),
                isYtj:sessionStorage.getItem("isYtj"),
                contentHtml:"",
                isDialogPrint:"N",
                sysName:"",
                filepath:"",
                dialogVisible6:false
                
            }
        },
        created(){
            if(this.noclick){
                this.noclicks=this.noclick;
            }else{
                this.noclicks="Y"
            }
          if(this.isYtj=="Y"){
           
          }
          sessionStorage.setItem("listnames",this.listnames)
        },
        mounted(){
            
           this.loadData();

        },
        activated (){
            
           
        },
        methods:{
            
            setSearchVal(searchId,val){
                let index=-1;
                for(let i=0;i<this.searchStr2.length;i++){
                    let searchId_=this.searchStr2[i].searchId;
                    if(searchId_==searchId){
                        index=i;
                    }
                }
               
                this.$set(this.searchStr2[index],"val",val);
                
                this.goSearch();
            },
            
            loadHtmlContent(){
                let urls=this.url;
                urls=urls.indexOf("?")==-1 ? urls+"?token="+sessionStorage.getItem("token"):urls+"&token="+sessionStorage.getItem("token")
                this.$post("",urls,this.getSearchData2()).then(data=>{
                    if(data[0].msg){
                        this.$alert(data[0].msg)
                    }
                    this.contentHtml=unescape(data[0].content);
                })
            },
            returns(){
                history.back();
            },
            loadData(isDevOps){ 
                console.log("isDevOps===================="+isDevOps)
                this.loadDataChild(this.sKey,this.sKey2,this.company,this.searchs,this.listname,isDevOps)
            },
            
            loadDataChild(sKey,sKey2,company,searchs,listname,isDevOps){
               //model_key组成是最外面的系统名称/路由的key,model是路由文件路径，去掉最外层的系统名称
                let sef=this;
                this.buttonJsonRow=[];
                this.$post(this.appid,'api/view/commonListJson',{
                    sKey:sKey,
                    sKey2:sKey2,
                    company:escape(escape(company)),
                    search:escape(escape(searchs)),
                    listname:escape(escape(listname)),
                    appid:this.appid,
                    model:escape(escape(this.model)),
                    key:escape(this.model_key)
                }).then(data=>{
                    if(data[0].err_msg){
                        sef.loading=false;
                        this.$message.error('路由错误，请联系管理员');
                        return;
                    }
                    sef.defaultOrder=data[0].defaultOrder;
                    sef.multiOrder=data[0].multiOrder;
                    sef.dbModelkey=data[0].dbModelkey;
                    sef.list=data[0].list;
                    sef.searchStr=data[0].searchStr;
                    sef.buttonJson=[];
                    sef.sysName=data[0].systemName;
                    sef.filepath=data[0].wur_listname;
                    if(data[0].noClick){
                        this.noclicks=data[0].noClick
                    }
                    let buttonJsons=data[0].buttonJson;
                    if(buttonJsons){
                        for(let i=0;i<buttonJsons.length;i++){
                            if(buttonJsons[i].types!="row"){
                                sef.buttonJson.push(buttonJsons[i]);
                            }else{
                                sef.buttonJsonRow.push(buttonJsons[i]);
                            }
                        }
                    }
                    


                    sef.tabJson=data[0].tabJson;
                    sef.url=data[0].url;
                    if(this.searchs){
                        for(let key in this.searchs){
                            for(let i=0;i<data[0].searchStr.length;i++){
                                let field=data[0].searchStr[i].searchId;
                                
                                if(field==key){
                                    data[0].searchStr[i].val=this.searchs[key];
                                }
                            }
                        }
                    }
                    
                    sef.tabJson2=data[0].tabJson;
                    sef.showTable=true;
                    sef.loading=false;
                    sef.title=data[0].wur_title;
                    sef.listname=data[0].wur_listname;
                    sessionStorage.setItem("listnames",this.listname)
                    if(data[0].noPage=="Y")
                        sef.noPage=true;
                   
                   // if(this.isSearch!='N'){
                        if(sef.searchJson&&sef.searchJson.length>0)
                            sef.searchStr2=sef.searchJson
                        else
                            sef.searchStr2=data[0].searchStr;
                  //  }
                    
                    if(this.isPost=='Y'){
                        this.loadHtmlContent();
                    }
                    this.$emit("loadBtn",JSON.stringify(data[0].buttonJson))
                    this.$emit("loadDatad",this.filepath)
                })
            },
            setSearch(){
                if(this.searchs){
                    for(let key in this.searchs){
                        for(let i=0;i<this.searchStr2.length;i++){
                            let field=this.searchStr2[i].searchId;
                            
                            if(field==key){
                                this.searchStr2[i].vals=this.searchs[key];
                            }
                        }
                    }
                }
            },
           
            loadData2(){ //切换listname的时候使用，tab
                let sef=this;
                let sKey=this.sKey;
                let sKey2=this.sKey2;
                
                //目前用于结账处理的零售，就是选项卡下面的列表，是左右复杂结果的时候用，如果单页可以直接用listname
                if(this.listname.indexOf("modelId")!=-1){
                    let modelIds=this.listname.split(":");
                    let modelIds_=modelIds[1].split("#");
                    this.sKeyd2=modelIds_[0];
                    this.exkeyd=modelIds_[1];
                    this.isSearch2="Y"
                    this.listname="";
                    this.sKeyd="";
                    this.listType="double";
                }else{
                    this.listType="simple";
                }
                //单页用listname
                if(this.listType=="simple"){
                    this.showTable=false;
                    this.loading=true;
                    sef.defaultOrder=[];//初始化排序 ，不然切换选项卡，排序未变
                    this.$post(this.appid,'api/view/commonListJson',{
                        sKey:sKey,
                        sKey2:sKey2,
                        key:escape(this.model_key),
                        model:escape(escape(this.model)),
                        company:escape(escape(this.company)),
                        search:escape(escape(this.searchs)),
                        listname:escape(escape(this.listname))
                    }).then(data=>{
                        sef.list=data[0].list;
                        sef.defaultOrder=data[0].defaultOrder;
                      //  sef.searchStr=data[0].searchStr;
                        sef.url=data[0].url;
                      //  sef.searchStr2=data[0].searchStr;
                        sef.showTable=true;
                        sef.loading=false;
                        sef.isSearch2="Y"
                        if(data[0].noPage=="Y")
                            sef.noPage=true;
                        
                     /*   if(sef.searchJson.length>0)
                            sef.searchStr2=sef.searchJson
                            */
                    // sef.$refs.tableList.loadData();
                    })
                }
                
            },
            isShowTable(){
                this.showTable=true;
            },
            searchEvent(data){
                
                this.searchStr2=JSON.parse(data);
                if(this.isPost=='Y'){
                    this.loadHtmlContent();
                }
                if(this.listType=="double"){
                    this.$refs.tableList.loadData(this.searchStr2);
                }
              //  this.$refs.tableList.loadData();
            },
            getScrollTop(){
                return this.$refs.tableList.getScrollTop();
            },
            setScrollTop(top){
                this.$refs.tableList.setScrollTop(top);
            },
            tabEvent(data){
                this.page=1;
                let datas=JSON.parse(data);
                let isok=true;
                for(let i=0;i<datas.length;i++){
                    let isDateSelect=datas[i].isDateSelect;

                    if(datas[i].listname&&datas[i].listname!=this.listname){
                        this.listname=datas[i].listname;
                        
                        isok=false;
                        this.tabJson2=JSON.parse(data);//这里有个bug，如果添加了这行代码，有多发一次请求到后台
                        this.loadData2();//如果切换选项卡的时候，有listname则需要重新调用loadData2来改变列
                        //if(isDateSelect=="Y"){
                           
                        //}
                    }
                        
                }
                if(isok)
                    this.tabJson2=JSON.parse(data);
            },
            tabEvents(data){
                let datas=JSON.parse(data);
                let listname=datas.listname;
                if(listname!=this.listname){
                    this.listname=listname;
                    this.loadData2();
                }
            },
            getSearchData(){
                return this.$refs.tableList.getSearchData();
            },
            getSearchData2(){
                let data={};
                let dataEx={};
                for(let i=0;i<this.searchStr2.length;i++){
                    let searchId=this.searchStr2[i].searchId;
                    let val=this.searchStr2[i].val;
                    if(this.searchStr2[i].vals){
                        val=this.searchStr2[i].vals;
                    }
                    data[searchId]=val;
                    let _data={};
                    _data.field=this.searchStr2[i].field;
                    _data.searchType=this.searchStr2[i].searchType;
                    _data.searchOper=this.searchStr2[i].searchOper;
                    dataEx[searchId]=_data;

                }
                
                let _data_={}
                _data_.field=this.parentId;
                _data_.searchType="hidden";
                dataEx[this.parentId]=_data_;

                // data['tabStr']=JSON.stringify(this.tabJson);
                data.page=""+this.page;
                data.limit=""+this.limit;
                data.sKey=this.sKey;
                data.sKey2=this.sKey2;
                if(this.exId)
                    data.exId=this.exId;
                else 
                    data.exId="";
                data.listname=escape(this.listname);
                data.key=this.model_key;
                data['dataEx']=JSON.stringify(dataEx);
                data['data']=JSON.stringify(data);
                data['company']=this.company;
                data['model']=this.model;
                if(this.ordersList){
                    let order="";
                    for(let i=0;i<this.ordersList.length;i++){
                        let orderColumn=this.ordersList[i].orderColumn;
                        let orderState=this.ordersList[i].orderState;
                        orderState=orderState=="descending" ? "desc":orderState;
                        orderState=orderState=="ascending" ? "asc":orderState;

                        if(orderState){
                            order=order=="" ? orderColumn+" "+orderState:order+","+orderColumn+" "+orderState;
                        }
                    }
                    data["order"]=order;
                }
                
                return data;
            },
            initData(){
                this.$refs.tableList.initData();
            },
            prints(item){
                item=JSON.parse(item);
                let wb_msgs=item.wb_msg.split("#");
                let isPrint=wb_msgs.length>1 ? wb_msgs[1]:"N";
                let printData_={};
                printData_.printName=wb_msgs[0];
                printData_.sCurItem=item.sId;
                printData_.appid=item.appid;
                printData_.page="";
                printData_.limit="";
                printData_.sKey="";
                printData_.sKey2="";
                printData_.listname="";
                printData_.dataEx="";
                printData_.data="";
                printData_.company="";
                printData_.token=sessionStorage.getItem("token");
                printData_.isPrint=isPrint;
                this.printData=printData_;
                if(item.isDialog=='Y'){
                    this.isDialogPrint='Y';
                    this.dialogVisible6=true;
                }
            },
            btnClick(data){
                let item=JSON.parse(data);
                console.log(item,"btnClick==================")
                let wb_isEdit=item.wb_isEdit;
                let key=item.key;
                let params=item.params;
                let isOpen=true;
                let wb_msg=item.wb_msg;
                let appid=item.appid;
                let filename=item.filename;
                let exData=item.exData;
                var isOk=true;
              
                if(item.isDownLoad=="Y"){
                    const link = document.createElement("a"); //自己创建的a标签
                    link.href = this.curRow[key];
                    document.body.appendChild(link);
                    link.click();
                    document.body.removeChild(link);
                    window.URL.revokeObjectURL(this.curRow[key]);
                }else if(item.buttonName.indexOf("Excel")!=-1||item.buttonName.indexOf("导出")!=-1){

                       // alert(wb_msg)
                        let data=null;
                        try{
                            data=this.getSearchData();
                        }catch(e){
                            data=this.getSearchData2();
                        }
                        let wb_msgs=wb_msg.split("#")
                        let printName=wb_msg.split("#")[0];
                        for(let i=0;i<this.searchStr.length;i++){
                            let searchId=this.searchStr[i].searchId;
                            let vals=this.searchStr[i].vals;
                            printName=printName.replace(searchId,vals);
                        }
                        data.printName=printName;

                        if(wb_msgs.length>3){
                            data.listname=wb_msgs[3]
                        }
                        let url="/api/view/exportExcel";
                        let appid=this.appid;
                       
                        if(item.excelUrl){
                            url=item.excelUrl;
                            appid="";
                        }
                        if(url.indexOf("isDownA=Y")!=-1){
                            this.$post(appid,url,data).then(data=>{
                                
                                const link = document.createElement('a');
                                link.href = data[0].url;
                                link.setAttribute('download', data[0].filename);
                                link.click();
                            })
                        }else{
                            this.$exportExcel(appid,url,data)
                        }
                        
                         this.$message({
                            message: '正在进行导出操作，导出成功后，会弹出下载框，如果内容较多可能需要花费一定时间，请不要重复操作导出',
                            type: 'success'
                            });
                        isOk=false;
                }else if(item.buttonName.indexOf("打印")!=-1&&item.isPrint!="N"&&item.isPrint!="A"){
                        let data=null;
                        try{
                            data=this.getSearchData();
                        }catch(e){
                            data=this.getSearchData2();
                        }
                        
                        let sId="";
                        if(this.curRow){
                            sId=this.curRow[key];
                        }
                        if(wb_isEdit=="A"){//多选
                            if(this.curRows){
                                sId="";
                                for(let i=0;i<this.curRows.length;i++){
                                    let id=this.curRows[i][key];
                                    sId=sId=="" ? id:sId+","+id;
                                }
                            }
                        }
                        
                        let listname=data.listname;
                        let item_={};
                        item_.buttonName="打印"+wb_msg.split("#")[0];
                        let wb_msgs=wb_msg.split("#");
                        let isPrint=wb_msgs.length>1 ? wb_msgs[1]:"N";
                        listname=wb_msgs.length>3 ? wb_msgs[3]:listname;
                       
                        let printTitle=wb_msg.split("#")[0];
                        if(wb_msgs.length>=3&&wb_msgs[2]){
                            printTitle=wb_msgs[2]
                        }
                       
                        for(let i=0;i<this.searchStr.length;i++){
                            let searchId=this.searchStr[i].searchId;
                            let vals=this.searchStr[i].vals;
                           
                            printTitle=printTitle.replace(searchId,vals);
                        }
                        
                       // alert(unescape(data.listname))
                        if(sId==undefined||sId=="undefined")
                            sId="";
                        item_.url="/commonPrint?printName="+wb_msgs[0]+"&printTitle="+printTitle+"&appid="+appid+"&sCurItem="+sId+"&token="+sessionStorage.getItem("token")+"&page="+data.page+"&limit="+data.limit+"&sKey="+data.sKey+"&sKey2="+data.sKey2+"&listname="+listname+"&dataEx="+escape(data.dataEx)+"&data="+escape(data.data)+"&company="+escape(data.company)+"&isPrint="+isPrint;
                       
                        if(isPrint=="Y"||item.isDialog=='Y'){
                            
                            let printData_={};
                            printData_.printName=wb_msgs[0];
                            printData_.printTitle=printTitle;
                            printData_.sCurItem=sId;
                            printData_.appid=appid;
                            printData_.page=data.page;
                            printData_.limit=data.limit;
                            printData_.sKey=data.sKey;
                            printData_.sKey2=data.sKey2;
                            printData_.listname=listname;
                            printData_.dataEx=data.dataEx;
                            printData_.data=data.data;
                            printData_.company=data.company;
                            printData_.token=sessionStorage.getItem("token");
                            printData_.isPrint=isPrint;
                            this.printData=printData_;
                            if(item.isDialog=='Y'){
                                this.isDialogPrint='Y';
                                this.dialogVisible6=true;
                            }
                        }else
                            this.$parent.openWin(JSON.stringify(item_));
                        
                        isOk=false;
                }else if(item.isPrint=="A") {
                    let exkey_=JSON.parse(JSON.stringify(item.exkey));
                    /*for(let key in exkey_){
                        exkey_[key]=this.curRow[exkey_[key]];
                    }*/
                    let print=exkey_.print;
                    for(let i=0;i<print.length;i++){
                        let field=print[i].field;
                        if(field){
                            print[i].value=print[i].value.replace(field,this.curRow[field])
                        }
                    }
                    console.log("print=-===========");
                    console.log(print)
                    this.myUni.webView.postMessage({  
                        data: {  
                            action: "print",
                            data:print,
                            width:exkey_.width,
                            height:exkey_.height
                        },  
                    });
                    isOk=false;
                }
                if(isOk){
                    let filenamerow="";
                    let curRow_=this.curRow;
                   
                    if(wb_isEdit=="Y"&&this.curRow==null&&(this.curRows==null||this.curRows.length==0)){
                        isOpen=false;
                        this.$message.error('请先选择一条数据');
                    }else if(wb_isEdit=="Y"||key){
                        if(this.curRow==null&&this.curRows!=null&&this.curRows.length>0)
                            curRow_=this.curRows[0]
                        if(!params){
                            let url=item.url;
                            
                           
                            
                            let sId="";
                            if(curRow_)
                                sId=curRow_[key];
                            if(!sId)
                                sId="";
                            
                            if(wb_isEdit=="Y"&&sId==""){
                                 isOpen=false;
                                 this.$message.error('请先选择一条数据');
                            }
                            url=url.indexOf("?")==-1 ? url+"?sId="+sId:url+"&sId="+sId;
                           
                            item.sId=sId;
                           
                          
                        }

                    }else{
                        let url=item.url;
                        url=url.indexOf("?")==-1 ? url+"?sId=":url+"&sId=";
                        item.url=url;
                        item.sId="";

                        
                    }
                    
                    let paramJson={};
                    if(params){
                        let paramss=params.split(",");
                        let keys=key.split(",");
                        if(keys.length==paramss.length){
                            
                           
                            for(let hh=0;hh<keys.length;hh++){
                                let sId="";
                                if(curRow_)
                                    sId=curRow_[keys[hh]];
                                if(!sId)
                                    sId="";
                                
                                let url=item.url;
                                url=url.indexOf("?")==-1 ? url+"?"+paramss[hh]+"="+sId:url+"&"+paramss[hh]+"="+sId;
                                paramJson[paramss[hh]]=sId;
                                item.url=url;
                                 
                            }
                           
                            
                        }
                    }
                    //设置额外的值，给编辑界面用的，比如在列表上有个按钮，需要选中列表一条数据，然后点新增子表的按钮，则主表的主键值需要传到子表外键去
                    if(exData){
                        exData=exData.replace(/''/g,"\"");
                        exData=JSON.parse(exData);
                        for(let key in exData){
                            let val=exData[key];
                            if(curRow_){
                                exData[key]=curRow_[val];
                            }
                        }
                        item.exData=exData;
                    }
                    try{
                        if(curRow_!=null&&curRow_.filename){
                            filenamerow=curRow_.filename;
                        }
                    }catch(e){}
                    
                    if(filenamerow){
                        filename=filenamerow;
                    }
                    //alert(filenamerow)
                    let url=item.url;
                    url=url+"&param_key="+params;
                    url=url+"&appid="+appid;
                    url=url+"&filename2="+filename;
                    url=url+"&key="+item.modelKey;
                    url=url+"&fieldPath="+item.field;
                    url=url+"&model="+item.model;
                   
                     if(isOpen&&wb_msg==""){
                        item.url=url;
                        item.param_key=params;
                        item.params=paramJson;
                        item.appid=appid;
                        item.filename2=filename;
                        item.key=item.modelKey;
                        item.fieldPath=item.field;
                        
                        item.exId=this.exId;//主要用于在列表中打开另外一个列表（子表），在这个子表中又要打开编辑界面，这个值就是主表主键

                        let ids_="";
                        if(this.curRows){
                            for(let i=0;i<this.curRows.length;i++){
                                let id=this.curRows[i][key];
                                ids_=ids_=="" ? id:ids_+","+id;
                            }
                        }
                        item.ids=ids_;//多选，目前只要用于多选后，在点击按钮，打开一个界面
                        try{
                            this.$parent.openWin(JSON.stringify(item));
                        }catch(e){
                            this.$emit("openWin",JSON.stringify(item))
                        }
                        
                        
                    }else if(wb_msg!=""){
                        let url=item.url;
                        let key=item.key;

                        let ids="";
                        if(this.curRows){
                            for(let i=0;i<this.curRows.length;i++){
                                let id=this.curRows[i][key];
                                ids=ids=="" ? id:ids+","+id;
                            }
                        }else{
                            ids=this.curRow[key];
                        }
                       
                        if(!ids){
                            this.$alert('请先选择一行数据', '错误提示', {
                                confirmButtonText: '确定',
                                callback: action => {}
                            });
                            return;
                        }
                        let params=null;
                        try{
                            params=this.getSearchData();
                        }catch(e){
                            params=this.getSearchData2();
                        }
                        this.$confirm(wb_msg, '提示', {
                            confirmButtonText: '确定',
                            cancelButtonText: '取消',
                            type: 'warning'
                        }).then(() => {
                            params["ids"]=ids;
                            if(url.indexOf("filename")==-1){
                                params.filename=item.filename;
                            }
                            params["sCode"]=localStorage.getItem("sCode");

                            let urlss=url.split(",");
                            let urls=urlss[0].split("#");
                            let appid=item.appid;
                            if(urls.length>1){
                                appid=urls[0];
                                url=urls[1];
                            }
                            this.$post(appid,url,params).then(data=>{
                                if(data[0].status=="+OK"){
                                    if(urlss.length>1){
                                        let url_=urlss[1].split("#");
                                        this.$post(url_[0].replace("appid=",""),url_[1],params).then(data=>{
                                        });
                                    }
                                    this.$message({
                                        message: unescape(data[0].msg),
                                         type: 'success'
                                        });
                                    this.goSearch()
                                }else{
                                    this.$alert(unescape(data[0].msg), '错误提示', {
                                        confirmButtonText: '确定',
                                        callback: action => {}
                                    });
                                }
                            });
                        }).catch(() => {
                                    
                        });
                    }
                }
                
                
               // this.$parent.$parent.postMessage(data,'*');
            },
            rowClick(data){
                this.curRow=JSON.parse(data);
                this.curRow.rowIndex=this.index;
                this.$emit("rowClick",JSON.stringify(this.curRow));
                
            },
            rowDbClick(data){
                this.curRow=JSON.parse(data);
                this.curRow.rowIndex=this.index;
                this.curRow.dbModelkey=this.dbModelkey;
                this.$emit("rowDbClick",JSON.stringify(this.curRow));
            },
            empty(data){
                 this.$emit("empty","");
                 this.curRow=null;
                 this.curRows=null;
            },
            rowMultiClick(data){
                this.curRows=JSON.parse(data);
                let datas={};
                datas.rowIndex=this.index;
                datas.row=this.curRows;
                
                this.$emit("rowMultiClick",JSON.stringify(datas));

            },
            goSearch(){
                this.$refs.tableList.loadData();
            },
            openWin(data){
              
                try{
                    this.$parent.openWin(data);
                }catch(e){
                     this.$emit("openWin",data);
                }
                
            },

            goSearchs(data){
               
                this.$emit("goSearch",data);
                
            },
            setSearchs(searchs){
                this.searchs=searchs;
                this.loadData();
            },
            setSearchs2(searchs){
                console.log(this.searchs,"searchs=========")
                this.searchs=searchs;
               // this.setSearch();
               if(this.searchs){
                    for(let key in this.searchs){
                        for(let i=0;i<this.searchStr2.length;i++){
                            let field=this.searchStr2[i].searchId;
                            
                            if(field==key){
                                this.searchStr2[i].val=this.searchs[key];
                                //this.$set(this.searchStr2[i],"val",this.searchs[key])
                            }
                        }
                    }
                }
                console.log(this.searchStr2,"searchs=========")
                this.$refs.tableList.loadData();
            },
            countJson(data){
                this.$emit("countJson",data);
            }
        },
        watch:{
           
            searchStr:{
                 handler: function (newVal) {
                    
                },      
                deep: true    //深度监听
            },
            searchJson:{
                 handler: function (newVal) {
                    console.log("searchJson======================")
                     this.searchStr2=newVal;
                    this.setSearch();
                },      
                deep: true    //深度监听
               
            },
            searchs:{
                handler: function (newVal) {
                   
                    console.log("searchs======================")
                     this.setSearch();
                     this.loadData();
                }
            }
        }
    }
</script>

<style scoped  src="../../assets/css/commonList.css">
</style>
<style scoped>
.commonList_title_app{
    text-align:center ;
}
.commonList_title_app2{
    text-align:center;
    height:60px;
    padding-top:30px;
    box-sizing: border-box;
}
.commonList_title_ytj{
    text-align: center;
    font-size:22px;
    height:50px;
    line-height: 50px;
}
.jsonDialog>>>.jsoneditor-vue{
    height:100%;
    text-align:left;
}
.el-collapse-item__wrap{
    background:#fff;
}
.elrows{
    text-align:left;
}
</style>